<?php 
    include('../includes/db_connect.php');
	include('../functions/fonctions.php');

	$titre = 'CONNEXION';

	$ousername = '';
        //On verifie si le formulaire a ete envoye
        if(isset($_POST['authentification']))
        {
			if ($_POST['password']!='' and $_POST['login']!='')
			{
                //On echappe les variables pour pouvoir les mettre dans des requetes SQL
                if(get_magic_quotes_gpc())
                {
                        $login = mysql_real_escape_string(stripslashes($_POST['login']));
                        $password = stripslashes(htmlspecialchars($_POST['password']));
                }
                else
                {
                        $login = mysql_real_escape_string(htmlspecialchars($_POST['login']));
                        $password = mysql_real_escape_string(htmlspecialchars($_POST['password']));
                }
                //On recupere le mot de passe de lutilisateur
                $req = mysql_query('SELECT * FROM users WHERE login="'.$login.'"');
                $dn = mysql_fetch_array($req);
					//On le compare a celui quil a entre et on verifie si le membre existe
					if($dn['password']==md5crypt($password) and mysql_num_rows($req)>0)
					{
						if ($dn['etat']=='0' AND $dn['level']==1){
							
								//Sinon, on indique que le client doit upload sa CNI et son Plan de localisation
								$form = true;
								//Message a afficher si l\'utilisateur est pas activé
								$_SESSION['error_message'] = '<strong>Alerte!!!</strong> Vous êtes inscrit mais votre compte est désactivé';
							} else {
							//Si le mot de passe es bon, on ne vas pas afficher le formulaire
							$form = false;
							//On enregistre son pseudo dans la session username et son identifiant dans la session userid
							$_SESSION['logged'] = time();
							$_SESSION['userid'] = $dn['id'];
							$_SESSION['nom'] = $dn['noms'];
							$_SESSION['login'] = $dn['login'];
							$_SESSION['prenom'] = $dn['prenoms'];
							$_SESSION['level'] = $dn['level'];
							$_SESSION['inscription'] = $dn['inscription'];
							
                            //On indique ici la date et l'heure de la dernier connexion'
                            mysql_query('UPDATE users SET last_conn="'.date("Y-m-d H:i:s").'" WHERE id="'.$_SESSION['userid'].'"');
						      /*TODO: Rediriger vers une page qui aurait voulu etre ouverte
                              if (isset($_SESSION['next'])){ //Une page suivante existe
                                //On redirige l'utilisteur vers la page en question'
						          forceRedirect($_SESSION['next']);
                                  unset($_SESSION['next']);
						      } else {
						          //On le redirige vers le tableau de bord
						          forceRedirect('../index.php');
						      }*/
                              //On le redirige vers le tableau de bord
						          forceRedirect('../index.php');
						       
						 }
					   
				   } else { 
							//Sinon, on indique que la combinaison nest pas bonne
							$form = true;
							$alertType = ' alert-error';
							$_SESSION['error_message'] = '<strong>Désolé!!!</strong> La combinaison que vous avez entr&eacute; n\'est pas bonne.';
				   }
			}
		}
        else
        {
                $form = true;
        } 
	
?>	
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title><?php echo $titre; ?></title>

<script src="js/jquery-1.5.2.min.js"></script>
<link rel="stylesheet" href="css/animate.min.css" type="text/css" />
<link rel="stylesheet" href="css/animate.delay.css" type="text/css" />
<style>
p,div,span,a,form,img,h1,button {
	background: transparent;
	border: 0;
	margin: 0;
	padding: 0;
	vertical-align: baseline;
}
body.loginbody { background: #f7f7f7 url(images/bg.png); }

.loginwrapper { width: 400px; margin: 40px auto 0 auto; }
.loginwrap { 
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-box-shadow: 0px 2px 5px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow:    0px 2px 5px 0px rgba(50, 50, 50, 0.75);
box-shadow:         0px 2px 5px 0px rgba(50, 50, 50, 0.75);}
.loginwrapper p { margin: 20px 0; }
.loginwrapper p:first-child { margin-top: 0;
 }
.loginwrapper p:last-child { margin-bottom: 0;   }
.logintitle { 
	padding: 15px; text-transform: uppercase; line-height: 21px; /*border: 1px solid #bbb;*/ font-size: 18px; border-bottom: 0;
	color: #666; -webkit-border-top-left-radius: 10px; -webkit-border-top-right-radius: 10px; -moz-border-radius-topleft: 10px;  -moz-border-radius-topright: 10px; border-top-left-radius: 10px; border-top-right-radius: 10px;
}
.logintitle span.iconfa-lock { font-size: 24px; margin-top: 0px; float: left; margin-right: 10px; }
.logintitle span.subtitle { font-size: 12px; font-weight: normal; display: block; margin-left: 32px; text-transform: none; color: #999; }
.logintitle span.connexion { font-family:Arial, Helvetica, sans-serif; font-size:24px; text-shadow: 1px 2px 0 rgba(0,0,0,0.4),
             -1px -2px 0 rgba(255,255,255,1); color:#2860B3;}
.loginwrapperinner { 
	padding: 20px; 
	background: #e2e2e2; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: #e2e2e2; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url();
background: -moz-linear-gradient(top,  #e2e2e2 70%, #ededed 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(70%,#e2e2e2), color-stop(100%,#ededed)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #e2e2e2 70%,#ededed 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #e2e2e2 70%,#ededed 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #e2e2e2 70%,#ededed 100%); /* IE10+ */
background: linear-gradient(to bottom,  #e2e2e2 70%,#ededed 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e2e2e2', endColorstr='#ededed',GradientType=0 ); /* IE6-8 */

	-moz-border-radius: 0 0 2px 2px; -webkit-border-radius: 0 0 2px 2px; border-radius: 0 0 2px 2px; -webkit-border-bottom-right-radius: 10px; -webkit-border-bottom-left-radius: 10px; -moz-border-radius-bottomright: 10px; -moz-border-radius-bottomleft: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px;
	
}
.loginshadow { background: url(shadow.png) no-repeat center center; height: 30px; }
.loginwrapper input { 
	width: 100%; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;
	padding: 10px; min-height: 44px; font-size: 14px !important; border: 0; color: #999;
	background: #eee; padding-left: 30px; 
}
.loginwrapper input#username { background: url(images/uname.png) no-repeat 8px 12px, #ffffff ;  /*Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */

background: url(images/uname.png) no-repeat 8px 12px, -moz-linear-gradient(top,  #ffffff 0%, #ececec 100%) ; /* FF3.6+ */
background: url(images/uname.png) no-repeat 8px 12px, -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#ececec)) ; /* Chrome,Safari4+ */
background: url(images/uname.png) no-repeat 8px 12px, -webkit-linear-gradient(top,  #ffffff 0%,#ececec 100%) ; /* Chrome10+,Safari5.1+ */
background: url(images/uname.png) no-repeat 8px 12px, -o-linear-gradient(top,  #ffffff 0%,#ececec 100%) ; /* Opera 11.10+ */
background: url(images/uname.png) no-repeat 8px 12px, -ms-linear-gradient(top,  #ffffff 0%,#ececec 100%) ; /* IE10+ */
background: url(images/uname.png) no-repeat 8px 12px, linear-gradient(to bottom,  #ffffff 0%,#ececec 100%) ; /* W3C */
filter: url(images/uname.png) no-repeat 8px 12px, progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ececec',GradientType=0 ) ; /* IE6-8 */
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: #d0d0d0 1px solid;
 }
.loginwrapper input#password { background: url(images/password.png) no-repeat 8px 12px, #ffffff ;  /*Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */

background: url(images/password.png) no-repeat 8px 12px, -moz-linear-gradient(top,  #ffffff 0%, #ececec 100%) ; /* FF3.6+ */
background: url(images/password.png) no-repeat 8px 12px, -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#ececec)) ; /* Chrome,Safari4+ */
background: url(images/password.png) no-repeat 8px 12px, -webkit-linear-gradient(top,  #ffffff 0%,#ececec 100%) ; /* Chrome10+,Safari5.1+ */
background: url(images/password.png) no-repeat 8px 12px, -o-linear-gradient(top,  #ffffff 0%,#ececec 100%) ; /* Opera 11.10+ */
background: url(images/password.png) no-repeat 8px 12px, -ms-linear-gradient(top,  #ffffff 0%,#ececec 100%) ; /* IE10+ */
background: url(images/password.png) no-repeat 8px 12px, linear-gradient(to bottom,  #ffffff 0%,#ececec 100%) ; /* W3C */
filter: url(images/password.png) no-repeat 8px 12px, progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ececec',GradientType=0 ) ; /* IE6-8 */
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: #d0d0d0 1px solid;
 }
.loginwrapper input#username.error,
.loginwrapper input#password.error { background-color: #ffeaea; color: #ff0000; }
.loginwrapper input:focus { 
	background-color: #fff;
	color: #666 !important; 
	box-shadow: 0 0 8px rgba(0,0,0,0.8) !important;
}
.loginwrapper button.btn { 
	padding: 12px 5px; border: 0; text-transform: uppercase; font-size: 13px; text-shadow: 1px 1px rgba(0,0,0,0.2);
	box-shadow: 0 2px 3px rgba(0,0,0,0.3); cursor:pointer; width:180px; margin:0px auto; 
}
.loginwrapper a { color: #999; }
.loginwrapper input, .loginwrapper a { 
	-moz-transition: all 0.2s ease-out 0s; -webkit-transition: all 0.2s ease-out 0s; transition: all 0.2s ease-out 0s; 
}
.btn { font-size: 12px; font-weight: bold; }
.btn-default {
	background: #4488e5; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url();
background: -moz-linear-gradient(top,  #4488e5 0%, #2860b3 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4488e5), color-stop(100%,#2860b3)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #4488e5 0%,#2860b3 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #4488e5 0%,#2860b3 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #4488e5 0%,#2860b3 100%); /* IE10+ */
background: linear-gradient(to bottom,  #4488e5 0%,#2860b3 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4488e5', endColorstr='#2860b3',GradientType=0 ); /* IE6-8 */

}
.btn-default:hover {
	background: #4e86b7; color: #fff; text-shadow: 1px 1px rgba(0,0,0,0.1);
	background: -moz-linear-gradient(top,  #4e86b7 0%, #035f9a 100%);
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4e86b7), color-stop(100%,#035f9a));
	background: -webkit-linear-gradient(top,  #4e86b7 0%,#035f9a 100%);
	background: -o-linear-gradient(top,  #4e86b7 0%,#035f9a 100%);
	background: -ms-linear-gradient(top,  #4e86b7 0%,#035f9a 100%);
	background: linear-gradient(to bottom,  #4e86b7 0%,#035f9a 100%);
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4e86b7', endColorstr='#035f9a',GradientType=0 );
}
.logintitle { 
	-moz-box-shadow: inset 0 1px 0 rgba(255,255,255,0.3); 
	-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,0.3); 
	box-shadow: inset 0 1px 0 rgba(255,255,255,0.3);
}
 .logintitle {
	background: #f7f7f7; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url();
background: -moz-linear-gradient(top,  #f7f7f7 0%, #e2e2e2 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f7f7f7), color-stop(100%,#e2e2e2)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #f7f7f7 0%,#e2e2e2 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #f7f7f7 0%,#e2e2e2 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #f7f7f7 0%,#e2e2e2 100%); /* IE10+ */
background: linear-gradient(to bottom,  #f7f7f7 0%,#e2e2e2 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f7f7f7', endColorstr='#e2e2e2',GradientType=0 ); /* IE6-8 */

}
.loginwrapper button.btn { -moz-border-radius: 2px; -webkit-border-radius: 2px; border-radius: 2px;}
</style>
</head>

<body class="loginbody">

<center><!--<h2>Connexion à l'application</h2>-->

<div class="loginwrapper">
	<div class="loginwrap zindex100 animate2 bounceInDown">
	<h1 class="logintitle"><span class="iconfa-lock"><img src="images/lock.png" /></span> <img alt="connexion" src="images/connexion.png" /> <span class="subtitle">Veuillez insérer votre login et votre mot de passe</span><br />
    <img src="images/ligne.png" alt="ligne de separation" /></h1>
<div class="loginwrapperinner">
            <?php //On affiche un message sil y a lieu
			if(isset($_SESSION['error_message']))
			{
				echo '<div class="alert alert-error">';
				echo '<button type="button" class="close" data-dismiss="alert">×</button>'.$_SESSION['error_message'].'</div>';
			} elseif(isset($_SESSION['success_message']))
			{
				echo '<div class="alert alert-success">';
				echo '<button type="button" class="close" data-dismiss="alert">×</button>'.$_SESSION['success_message'].'</div>';
			}
            ?>
        <form id="loginform" action="" method="post">
                <p class="animate4 bounceIn"><input type="text" id="login" name="login"  placeholder="Login" /></p>
                <p class="animate5 flip"><input type="password" id="password" name="password" placeholder="Mot de passe" /></p>
                <p class="animate6 wobble"><button class="btn btn-default btn-block" name="authentification" value="1"><img src="images/login.png" width="114" height="24" alt="login" /></button></p>
            </form>
        </div>
    </div>
    <!--<div class="loginshadow animate3 fadeInUp"></div>-->
</div>

</center>

<script type="text/javascript">
jQuery.noConflict();

jQuery(document).ready(function(){
	
	var anievent = (jQuery.browser.webkit)? 'webkitAnimationEnd' : 'animationend';
	jQuery('.loginwrap').bind(anievent,function(){
		jQuery(this).removeClass('animate2 bounceInDown');
	});
	
	jQuery('#username,#password').focus(function(){
		if(jQuery(this).hasClass('error')) jQuery(this).removeClass('error');
	});
	
	jQuery('#loginform button').click(function(){
		if(!jQuery.browser.msie) {
			if(jQuery('#username').val() == '' || jQuery('#password').val() == '') {
				if(jQuery('#username').val() == '') jQuery('#username').addClass('error'); else jQuery('#username').removeClass('error');
				if(jQuery('#password').val() == '') jQuery('#password').addClass('error'); else jQuery('#password').removeClass('error');
				jQuery('.loginwrap').addClass('animate0 wobble').bind(anievent,function(){
					jQuery(this).removeClass('animate0 wobble');
				});
			} else {
				jQuery('.loginwrapper').addClass('animate0 fadeOutUp').bind(anievent,function(){
					jQuery('#loginform').submit();
				});
			}
			return false;
		}
	});
});
</script>



</body>
</html>
